package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_bonus_detail;

import cn.com.api.service.ApiU_bonus_detailService;

import cn.com.util.*;
import cn.com.util.*;


public class U_bonus_detailBaseController {

	private static Logger logger = Logger.getLogger(U_bonus_detailBaseController.class);
	
	@Autowired
	private ApiU_bonus_detailService apiU_bonus_detailService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "u_bonus_detail-list")
	public ModelAndView u_bonus_detail_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_bonus_detail_list.jsp");
		
		List<ApiU_bonus_detail> u_bonus_details = apiU_bonus_detailService.findU_bonus_details();
		mv.addObject("u_bonus_details", u_bonus_details);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "u_bonus_detail-add-pre")
	public ModelAndView u_bonus_detail_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_bonus_detail_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiU_bonus_detail u_bonus_detail = apiU_bonus_detailService.findU_bonus_detailById(Integer.valueOf(id));
			mv.addObject("u_bonus_detail",u_bonus_detail);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "u_bonus_detail-add")
	public void u_bonus_detail_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String id = request.getParameter("id");
		String bonus_id = request.getParameter("bonus_id");
		String money = request.getParameter("money");
		String is_max = request.getParameter("is_max");
		String get_time = request.getParameter("get_time");
		String get_uid = request.getParameter("get_uid");
		String get_uname = request.getParameter("get_uname");
		String get_uhead = request.getParameter("get_uhead");
		String status = request.getParameter("status");
		String ext1 = request.getParameter("ext1");
		String ext2 = request.getParameter("ext2");
		String ext3 = request.getParameter("ext3");
		String ext4 = request.getParameter("ext4");
		String ext5 = request.getParameter("ext5");
		String is_forward = request.getParameter("is_forward");
		String forward_word = request.getParameter("forward_word");
		
		Map<String,Object> map = new HashMap<String,Object>();
		//String id = request.getParameter("id");
		//add
		if(id==null || (id.trim()).equals("")){
			ApiU_bonus_detail u_bonus_detail = new ApiU_bonus_detail();
            /*
		    u_bonus_detail.setId(id);
		    u_bonus_detail.setBonus_id(bonus_id);
		    u_bonus_detail.setMoney(money);
		    u_bonus_detail.setIs_max(is_max);
		    u_bonus_detail.setGet_time(get_time);
		    u_bonus_detail.setGet_uid(get_uid);
		    u_bonus_detail.setGet_uname(get_uname);
		    u_bonus_detail.setGet_uhead(get_uhead);
		    u_bonus_detail.setStatus(status);
		    u_bonus_detail.setExt1(ext1);
		    u_bonus_detail.setExt2(ext2);
		    u_bonus_detail.setExt3(ext3);
		    u_bonus_detail.setExt4(ext4);
		    u_bonus_detail.setExt5(ext5);
		    u_bonus_detail.setIs_forward(is_forward);
		    u_bonus_detail.setForward_word(forward_word);
	        */
			apiU_bonus_detailService.insertU_bonus_detail(u_bonus_detail);
		}
		//edit
		else{
			ApiU_bonus_detail u_bonus_detail = apiU_bonus_detailService.findU_bonus_detailById(Integer.valueOf(id));
	        /*
		    u_bonus_detail.setId(id);
		    u_bonus_detail.setBonus_id(bonus_id);
		    u_bonus_detail.setMoney(money);
		    u_bonus_detail.setIs_max(is_max);
		    u_bonus_detail.setGet_time(get_time);
		    u_bonus_detail.setGet_uid(get_uid);
		    u_bonus_detail.setGet_uname(get_uname);
		    u_bonus_detail.setGet_uhead(get_uhead);
		    u_bonus_detail.setStatus(status);
		    u_bonus_detail.setExt1(ext1);
		    u_bonus_detail.setExt2(ext2);
		    u_bonus_detail.setExt3(ext3);
		    u_bonus_detail.setExt4(ext4);
		    u_bonus_detail.setExt5(ext5);
		    u_bonus_detail.setIs_forward(is_forward);
		    u_bonus_detail.setForward_word(forward_word);
			*/
			apiU_bonus_detailService.updateU_bonus_detail(u_bonus_detail);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "u_bonus_detail-delete")
	public void u_bonus_detail_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiU_bonus_detailService.deleteU_bonus_detail(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}
	
}



